//
//  STViewModel.m
//  MusicGetPro
//
//  Created by aReu on 2017/3/16.
//  Copyright © 2017年 aReu. All rights reserved.
//

#import "STViewModel.h"
#import "aRquestModel.h"

@implementation STViewModel

-(instancetype)init {
    if (self = [super init]) {
        [self initRac];
    }
    return self;
}

-(void)initRac {
    
    @weakify(self);
    self.dCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            
            @strongify(self);
            NSInteger index = self.index;
            if (0 == index) {
                [aRquestModel requesWangyYunByName:_songName Block:^(NSMutableArray *arr) {
                    [subscriber sendNext:arr];
                    [subscriber sendCompleted];
                }];
            }else if (1 == index){
                [aRquestModel requestQQByName:_songName Block:^(NSMutableArray *arr) {
                    [subscriber sendNext:arr];
                    [subscriber sendCompleted];
                }];
            }else if (2 == index){
                [aRquestModel requesKuGouByName:_songName Block:^(NSMutableArray *arr) {
                    [subscriber sendNext:arr];
                    [subscriber sendCompleted];
                }];
            }else if (4 == index){
                [aRquestModel requesBanzouByName:_songName Block:^(NSMutableArray *arr) {
                    [subscriber sendNext:arr];
                    [subscriber sendCompleted];
                }];
            }

            return [RACDisposable disposableWithBlock:^{
                NSLog(@"Miss");
            }];
        }];
    }];
    
    
    
    
//    self.dSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//        @strongify(self);
//        NSInteger index = self.index;
//        if (0 == index) {
//            [aRquestModel requesWangyYunByName:_songName Block:^(NSMutableArray *arr) {
//                [subscriber sendNext:arr];
//            }];
//        }else if (1 == index){
//            [aRquestModel requestQQByName:_songName Block:^(NSMutableArray *arr) {
//                [subscriber sendNext:arr];
//            }];
//        }else if (2 == index){
//            [aRquestModel requesKuGouByName:_songName Block:^(NSMutableArray *arr) {
//                [subscriber sendNext:arr];
//            }];
//        }else if (4 == index){
//            [aRquestModel requesBanzouByName:_songName Block:^(NSMutableArray *arr) {
//               [subscriber sendNext:arr];
//            }];
//        }
//        return [RACDisposable disposableWithBlock:^{
//            NSLog(@"Miss");
//        }];
//    }];
}


@end
